<?
session_start();
include 'php/connect.php';

$action = mysql_real_escape_string($_POST['action']);

				
if ($action=="send"){

	$output = json_encode(array("status"=>"error","message"=>"nok"));
	
	$do = mysql_real_escape_string($_POST['dos']);
	$expect = mysql_real_escape_string($_POST['expect']);
	$see = mysql_real_escape_string($_POST['see']);
	$add = mysql_real_escape_string($_POST['add']);
	$email = mysql_real_escape_string($_POST['email']);
	
	/* TODO SEND MAIL */
	
	$Name = "[FFXIVSpecs]"; //senders name
	$sender = $email; //senders e-mail adress
	$recipient = "ffxivspecs@gmail.com"; //recipient
	$mail_body = "Report:\n\n 
					What did you do:\n
					".$do."\n\n
					What did you expect:\n
					".$expect."\n\n
					What did you see:\n
					".$see."\n\n
					Additional comments:\n
					".$add."\n\n"; //mail body
	$subject = "FFXIVSpecs Bug report"; //subject
	$header = "From: ". $Name . " <" . $sender . ">\r\n"; //optional headerfields 

	ini_set('sendmail_from', 'me@ffxivspecs.com'); 

	if(mail($recipient, $subject, $mail_body, $header)){
		$output = json_encode(array("status"=>"success","message"=>"ok"));
	}
	
}else{
		$output .= "<html>
				<head>
					<!-- Bug Report -->
				</head>
				<script>
					function sendReport(){
						var params = {
								action: 'send'
								,dos:  $('#do').val()
								,expect: $('#expect').val()
								,see: $('#see').val()
								,add: $('#add').val()
								,email: $('#email').val()
								};
						$.post('bug.php' , params, function(data) {
						  if (data.status == 'success') {
								$('#status_message').html('Thank You for making this site better');
								$('#send-button').hide();
						  }else{
							var msg = 'Sorry but there was an error.';
							$('#status_message').html(msg);
							;
						  }
						}, 'json');
					}
				</script>
				<div class = 'content-title-container'>
					<div class='normal-text grey-text content-title-text fl-left'>Bug report</div>
				</div>
					<body>	
						<form class='marg-t-10' method='POST' action='javascript:sendReport();'>
							<table>
								<tr class='tr-table border-bottom'>
									<td class='td-table vertical-middle width-180'><div class='normal-text bold-text pad-l-50'>Your Email:</div></td>
									<td class='td-table vertical-middle width-180 pad-tb-5'><input id='email' class='text-area' style='height: 20px;' type='text'></textarea></td>
									<td class='td-table vertical-middle'><div id='do_err' class='normal-text bold-text marg-l error-container'></div></td>
								</tr>
								<tr class='tr-table border-bottom'>
									<td class='td-table vertical-middle width-180'><div class='normal-text bold-text pad-l-50'>What did you do?</div></td>
									<td class='td-table vertical-middle width-180 pad-tb-5'><textarea id='do' class='text-area' type='text'></textarea></td>
									<td class='td-table vertical-middle'><div id='do_err' class='normal-text bold-text marg-l error-container'></div></td>
								</tr>
								<tr class='tr-table border-bottom'>
									<td class='td-table vertical-middle width-180'><div class='normal-text bold-text pad-l-50'>What did you expect?</div></td>
									<td class='td-table vertical-middle width-180 pad-tb-5'><textarea id='expect' class='text-area' type='text'></textarea></td>
									<td class='td-table vertical-middle'><div id='expect_err' class='normal-text bold-text marg-l error-container'></div></td>
								</tr>
								
								<tr class='tr-table border-bottom'>
									<td class='td-table vertical-middle width-180'><div class='normal-text bold-text pad-l-50'>What did you see?</div></td>
									<td class='td-table vertical-middle width-180 pad-tb-5'><textarea id='see' class='text-area' type='text'></textarea></td>
									<td class='td-table vertical-middle'><div id='see_err' class='normal-text bold-text marg-l error-container'></div></td>
								</tr>
								<tr class='tr-table border-bottom'>
									<td class='td-table vertical-middle width-180'><div class='normal-text bold-text pad-l-50'>Additional comment?</div></td>
									<td class='td-table vertical-middle width-180 pad-tb-5'><textarea id='add' class='text-area' type='text'></textarea></td>
									<td class='td-table vertical-middle'><div id='add_err' class='normal-text bold-text marg-l error-container'></div></td>
								</tr>
								<tr class='tr-table'>
									<td class='td-table vertical-middle pad-tb-5' colspan='2'><div id='status_message' class='normal-text bold-text error-container'></div></td>
									<td class='td-table vertical-middle horizontal-right' ><div id='save-submit-button'><input id='send-button' type='submit' value='Send'/></div></td>
								</tr>
							</table>
						</form>
					</body>
				</html>
				";
}
echo $output;

?>
